package org.zuoye.DaoImp;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.zuoye.util.HibernateSessionFactory;
import org.zuoye.bean.UserLogin;
import org.zuoye.Dao.loginDao;

public class loginDaoimp implements loginDao{

	@Override
	public UserLogin isLogin(String userName, String userPassword) {
		Session session=null;
		Transaction tx=null;
		UserLogin login=null;
		try{
			session=HibernateSessionFactory.getSession();
			tx=session.beginTransaction();
			Query query=session.createQuery("from UserLogin where userName=? and userPassword=?");
			query.setParameter(0, userName);
			query.setParameter(1, userPassword);
			query.setMaxResults(1);
			login=(UserLogin) query.uniqueResult();
			tx.commit();
		}catch(Exception e){
			if(tx!=null)tx.rollback();
			e.printStackTrace();
		}
		return login;
	}

}
